package com.jtpay.ysfproductionprocess.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class YSFDBHelper extends SQLiteOpenHelper {
    private static final String SQL_CREATE_TABLE = "CREATE TABLE ";
    private static final String SQL_DROP_TABLE = "DROP TABLE IF EXISTS ";
    private static final String SQL_PRIMARY_KEY = " INTEGER PRIMARY KEY AUTOINCREMENT";
    private static final String SQL_PRIMARY_KEY_DEFAULT_0 = " INTEGER DEFAULT 0";
    private static final String SQL_TEXT = " TEXT";
    private static final String SQL_COMMA = ",";
    private static final String DATABASE_NAME = "ysfproduct.db";
    private static final int VERSION = 1;

    public YSFDBHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        // 创建加密表
        database.execSQL(SQL_CREATE_TABLE + YSFEncryptColumn._TABLE_NAME
                + " (" + YSFBaseColumn._ID + SQL_PRIMARY_KEY + SQL_COMMA
                + YSFBaseColumn._MONEY + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._REMARK + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._INPUT + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._OUTPUT + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._IS_OK + SQL_PRIMARY_KEY_DEFAULT_0 + SQL_COMMA
                + YSFEncryptColumn._TYPE + SQL_PRIMARY_KEY_DEFAULT_0
                + ");"
        );
        // 创建解密表
        database.execSQL(SQL_CREATE_TABLE + YSFDecryptColumn._TABLE_NAME
                + " (" + YSFBaseColumn._ID + SQL_PRIMARY_KEY + SQL_COMMA
                + YSFBaseColumn._MONEY + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._REMARK + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._INPUT + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._OUTPUT + SQL_TEXT + SQL_COMMA
                + YSFBaseColumn._IS_OK + SQL_PRIMARY_KEY_DEFAULT_0 + SQL_COMMA
                + YSFDecryptColumn._TYPE + SQL_PRIMARY_KEY_DEFAULT_0
                + ");"
        );

    }

    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
        database.execSQL(SQL_DROP_TABLE + YSFEncryptColumn._TABLE_NAME);
        database.execSQL(SQL_DROP_TABLE + YSFDecryptColumn._TABLE_NAME);
    }
}
